Python/File Handling in Python section 1 Sample Test,Sample questions

Question:
 Which statement will read 5 characters from a file(file object ‘f’)?

1.f.read()

2.f.read(5)

3.f.reads(5)

4.None of the above

Posted Date:-2021-12-12 06:03:00


Question:
 A _____ file consists of human readable characters.

1.Binary

2. Text

3.Both of the above

4.None of the above

Posted Date:-2021-12-12 06:52:14


Question:
 Almost all the files in our computer stored as _______ File

1.Text

2.Binary

3.CSV

4.None of the above

Posted Date:-2021-12-12 06:38:39


Question:
 Fill in the blank


import pickle
f=open("data.dat",'rb')
d=_____________________.load(f)
f.close()

1.unpickle

2.pickling

3.pickle

4. pick

Posted Date:-2021-12-12 06:24:13


Question:
 open( ) function takes ____ as parameter.

1.File name

2.Access mode

3.Both of the above

4.None of the above

Posted Date:-2021-12-12 06:56:45


Question:
 Ravi opened the file myfile.txt in append mode. In this file the file object/file handle will be at the ___

1.beginning of the file

2.end of the file

3. second line of the file

4.the end of the first line

Posted Date:-2021-12-12 07:07:45


Question:
 Refer to the above code (Q 47) : Write the output of Third Print Statement

1.e to m

2.e to my

3.to my

4. None of the above

Posted Date:-2021-12-12 06:50:15


Question:
 The syntax of seek() is: file_object.seek(offset [, reference_point])
What is reference_point indicate?

1. reference_point indicates the starting position of the file object

2.reference_point indicates the ending position of the file object

3.reference_point indicates the current position of the file object

4.None of the above

Posted Date:-2021-12-12 06:19:04


Question:
 When we open file in append mode the file pointer is at the _________ of the file.

1.end

2.beginning

3.anywhere in between the file

4.second line of the file

Posted Date:-2021-12-12 06:47:16


Question:
 Which function is used to write data in binary mode?

1.write

2.writelines

3.pickle

4.dump

Posted Date:-2021-12-12 06:14:09


Question:
 Which of the following is an invalid mode of file opening?

1.read only mode

2. write only mode

3.read and write mode

4.write and append mode

Posted Date:-2021-12-12 06:20:31


Question:
 Which statement will open file “data.txt” in append mode?

1.f = open(“data.txt” , “a”)

2.f = Open(“data.txt” , “ab”)

3.f = new(“data.txt” , “a”)

4.open(“data.txt” , “a”)

Posted Date:-2021-12-12 06:23:33


Question:
 Write the output of the following:
>>> f = open("test.txt","w")
>>> f.close()
>>> f.closed

1.True

2.False

3.yes

4.No

Posted Date:-2021-12-12 07:01:46


Question:
A _____________ is a named location on a secondary storage media where data are permanently stored for later access

1. file

2.variable

3.comment

4.token

Posted Date:-2021-12-12 06:51:35


Question:
Default EOL character in text file is _____

1.

2. N

3.

4. l

Posted Date:-2021-12-12 06:54:57


Question:
Each line of a text file is terminated by a special character, called the ____

1.End of File

2.End of Line

3.End of Statement

4. End of program

Posted Date:-2021-12-12 06:54:17


Question:
EOF stands for ___________

1. End of File

2.End off File

3.End on File

4.End or Fil

Posted Date:-2021-12-12 06:09:42


Question:
f.seek(10,0) will move 10 bytes forward from beginning of file.

1.True

2.False

3.yes

4.Error

Posted Date:-2021-12-12 06:45:40


Question:
File in python is treated as sequence of ________________

1.Bytes

2.Bites

3.bits

4.None of the above

Posted Date:-2021-12-12 06:13:22


Question:
Fill in the blanks in the following code of writing data in binary files. Choose the answer for statement 1
import ___________   # Statement 1
rec = [ ]
while True:
     rn = int(input("Enter"))
     nm = input("Enter")
     temp = [rn, nm]
     rec.append(temp)
     ch = input("Enter choice (Y/N)")
     if ch.upper == "N":
          break
f = open("stud.dat", "____________")  #statement 2
__________ .dump(rec, f)   #statement 3
_______.close( ) # statement 4

1.csv

2.unpickle

3.pickle

4.load

Posted Date:-2021-12-12 06:40:51


Question:
Identify the correct statement to open a file:

1.f = open(“D:\myfolder\naman.txt”)

2.f = open(“D:myfolder aman.txt”)

3. f = open(“D:myfolder#naman.txt”)

4.f = Open(“D:myfolder aman.txt”)

Posted Date:-2021-12-12 06:57:27


Question:
Identify the invalid mode from the following.

1. a

2.. r+

3.ar+

4.w

Posted Date:-2021-12-12 06:19:44


Question:
In the given statement, the file myfile.txt will open in _______________ mode.
myObject=open(“myfile.txt”, “a+”)

1.append and read

2.append and write

3.append and read and binary

4.All the above

Posted Date:-2021-12-12 07:06:38


Question:
In which of the following data store permanently?

1.File

2.Variable

3.Both of the above

4.None of the above

Posted Date:-2021-12-12 06:56:10


Question:
Let the file pointer is at the end of 3rd line in a text file named “data.txt”. Which of the following option can be used to read all the remaining lines?

1.f.read( )

2.f.read(all)

3.f.readline( )

4.f.readlines( )

Posted Date:-2021-12-12 06:16:06


Question:
open( ) function returns a file object called _____

1.object handle

2. file handle

3.read handle

4.write handle

Posted Date:-2021-12-12 07:12:24


Question:
pdf and .doc are examples of __________ files.

1.Text

2.Binary

3.CSV

4.None of the above

Posted Date:-2021-12-12 06:39:19


Question:
Ram opened a file in a certain mode. After opening the file, he forgot the mode. The interesting facts about that mode are ” If the file doesn’t exist, then a new file will be created” and “After opening file in that mode the file handle will be at the end of the file” Help him to identify the correct mode.

1.read mode

2.write mode

3.append mode

4. binary and read mode

Posted Date:-2021-12-12 07:10:37


Question:
Ravi opened a file in a certain mode. After opening the file, he forgot the mode. One interesting fact about that mode is ” If the file already exists, all the contents will be overwritten”. Help him to identify the correct mode.

1.read mode

2.write mode

3.append mode

4.binary and read mode

Posted Date:-2021-12-12 07:09:45


Question:
Ravi opened a file in python using open( ) function but forgot to specify the mode. In which mode the file will open?

1.write

2.append

3.read

4.read and write both

Posted Date:-2021-12-12 07:02:57


Question:
Ravi opened the file myfile.txt in write mode. In this file the file object/file handle will be at the __

1.beginning of the file

2.end of the file

3.second line of the file

4.the end of the first line

Posted Date:-2021-12-12 07:08:22


Question:
readlines( ) function returns all the words of the file in the form of List. (T/F)

1.True

2.False

3.yes

4.Error

Posted Date:-2021-12-12 06:21:14


Question:
readlines() method return _________

1.String

2.List

3.Dictionary

4.Tuple

Posted Date:-2021-12-12 06:08:47


Question:
Refer to the above code (Q 38)and choose the option for statement 3

1.unpickle

2.write

3.pickle

4.None of the above

Posted Date:-2021-12-12 06:42:30


Question:
Refer to the above code (Q 38)and choose the option for statement 4.

1.f

2.rec

3.file

4.stud

Posted Date:-2021-12-12 06:43:32


Question:
Refer to the above code (Q 47) : Write the output of Fourth Print Statement

1.17

2.16

3.19

4.18

Posted Date:-2021-12-12 06:51:08


Question:
Refer to the above code (Q 47) : Write the output of Second Print Statement

1.om

2.me

3.co

4.None of the above

Posted Date:-2021-12-12 06:49:33


Question:
Refer to the above code and choose the option for statement2.

1.w

2.w+

3.wb

4.write

Posted Date:-2021-12-12 06:41:40


Question:
The syntax of seek() is:file_object.seek(offset [, reference_point] What is the default value of reference_point

1.0

2.1

3.2

4.3

Posted Date:-2021-12-12 06:44:11


Question:
The syntax of seek() is:file_object.seek(offset [, reference_point]) What all values can be given as a reference point?

1.1

2.2

3.0

4.All of the above

Posted Date:-2021-12-12 06:39:59


Question:
What error is returned by the following statement if the file does not exist?
f=open("A.txt")

1.FileNotFoundError

2. NotFoundError

3.NotFoundError

4.FoundError

Posted Date:-2021-12-12 06:36:08


Question:
What is ‘f’ in the following statement?
f=open("Data.txt" , "r")

1. File Name

2.File Handle

3.Mode of file

4.File Handling

Posted Date:-2021-12-12 06:22:02


Question:
What is full form of CSV

1.Comma Separation Value

2.Comma Separated Value

3.Common Syntax Value

4.Comma Separated Variable

Posted Date:-2021-12-12 06:22:58


Question:
When we open file in write mode the file pointer is at the _______ of the file.

1.end

2.beginning

3.anywhere in between the file

4.second line of the file

Posted Date:-2021-12-12 06:48:19


Question:
Which function is used to force transfer of data from buffer to file?

1. flush( )

2.save( )

3.move( )

4.None of the above

Posted Date:-2021-12-12 06:14:54


Question:
Which function is used to read data from Text File?

1.a. read( )

2.writelines( )

3.pickle( )

4.dump( )

Posted Date:-2021-12-12 06:10:24


Question:
Which function open file in python?

1.open( )

2.new( )

3.Open( )

4.None of the above

Posted Date:-2021-12-12 06:03:51


Question:
Which mode create new file if the file does not exist?

1.write mode

2.append mode

3.Both of the above

4.None of the above

Posted Date:-2021-12-12 06:07:02


Question:
Which module to be imported to make the following line functional?
sys.stdout.write("ABC")

1.system

2.sys

3.stdout

4.stdin

Posted Date:-2021-12-12 06:24:47


Question:
Which of the following are the attributes of file handle?

1.closed

2.name

3.mode

4.All the above

Posted Date:-2021-12-12 06:58:32


Question:
Which of the following attribute of file handle returns Boolean value?

1.name

2.closed

3.mode

4.None of the above

Posted Date:-2021-12-12 07:02:17


Question:
Which of the following error is returned when we try to open a file in write mode which does not exist?

1.FileNotFoundError

2.FileFoundError

3.FileNotExistError

4.None of the above

Posted Date:-2021-12-12 06:17:30


Question:
Which of the following file can be created in python?

1.Text File

2. Binary File

3.CSV File

4.All the above

Posted Date:-2021-12-12 06:55:33


Question:
Which of the following file can be opened in any text editor?

1. Binary

2.Text

3.Both of the above

4.None of the above

Posted Date:-2021-12-12 06:53:35


Question:
Which of the following file require specific programs to access its contents?

1.Binary

2.Text

3.CSV

4.None of the above

Posted Date:-2021-12-12 06:52:54


Question:
Which of the following function is used to close the file?

1. close( )

2.end( )

3.quit( )

4.exit( )

Posted Date:-2021-12-12 07:11:23


Question:
Which of the following function takes two arguments?

1. load( )

2.dump( )

3.Both of the above

4.None of the above

Posted Date:-2021-12-12 06:38:00


Question:
Which of the following is invalid mode of opening file?

1.r

2.rb

3.+r

4.None of the above

Posted Date:-2021-12-12 07:03:44


Question:
Which of the following is the valid way to open the file?

1. with open (file_name, access_mode) as fo:

2.fo = open (file_name, access_mode)

3.Both of the above

4.None of the above

Posted Date:-2021-12-12 07:13:09


Question:
Which of the following mode will create a new file, if the file does not exist?

1. ‘a’

2.‘a+

3. ‘+a’

4.All the above

Posted Date:-2021-12-12 07:04:23


Question:
Which of the following mode will open the file in binary and read-only mode.

1. ‘r’

2. ‘rb’

3.‘r+’

4. ‘rb+’

Posted Date:-2021-12-12 07:05:17


Question:
Which of the following mode will opens the file in read, write and binary mode?

1.‘wb+

2.‘+wb’

3.Both of the above

4.None of the above

Posted Date:-2021-12-12 07:05:58


Question:
Which of the following options can be used to read the first line of a text file data.txt?

1.f = open(‘data.txt’); f.read()

2. f = open(‘data.txt’,’r’); f.read(n)

3.myfile = open(‘data.txt’); f.readline()

4. f = open(‘data.txt’); f.readlines()

Posted Date:-2021-12-12 06:12:50


Question:
Which of the following will read entire content of file(file object ‘f’)?

1. f.reads( )

2.f.read( )

3.f.read(all)

4.f.read( * )

Posted Date:-2021-12-12 06:11:07


Question:
Which statement will move file pointer 10 bytes backward from current position.

1.Which statement will move file pointer 10 bytes backward from current position. a. f.seek(-10, 0)

2.f.seek(10, 0)

3. f.seek(-10, 1)

4.None of the above

Posted Date:-2021-12-12 06:46:32


Question:
Which statement will return error?
import pickle
f=open("data.dat",'rb')
d=pickle.load(f)
f.end()

1.Statement 1

2.Statement 2

3.Statement 3

4. Statement 4

Posted Date:-2021-12-12 06:37:23


Question:
Which statement will return one line from a file (file object is ‘f’)?

1. f.readline( )

2.f.readlines( )

3.f.read( )

4. f.line( )

Posted Date:-2021-12-12 06:08:08


Question:
Which symbol is used for append mode?

1. ap

2.a

3.w

4.app

Posted Date:-2021-12-12 06:11:50


Question:
Write the output of the First Print statements :
f=open("data.txt",'w')
f.write("Hello")
f.write("Welcome to my Blog")
f.close()
f=open("data.txt",'r')
d=f.read(5)
print(d) # First Print Statement
f.seek(10)
d=f.read(3)
print(d) # Second Print Statement
f.seek(13)
d=f.read(5)
print(d) # Third Print Statement
d=f.tell()
print(d) # Fourth Print Statement

1.Hello

2.Hell

3.ello

4.None of the above

Posted Date:-2021-12-12 06:48:58


Question:
Write the output of the following:
>>> f = open("test.txt","w")
>>> f.closed

1.True

2.False

3.yes

4.Error

Posted Date:-2021-12-12 06:59:28


Question:
Write the output of the following:
>>> f = open("test.txt","w")
>>> f.mode

1.‘w’

2.‘r’

3. ‘a’

4.w+’

Posted Date:-2021-12-12 07:00:11


Question:
Write the output of the following:
>>> f = open("test.txt","w")
>>> f.name

1.‘test’

2. ‘test.txt’

3.test.dat’

4.file does not exist

Posted Date:-2021-12-12 07:00:54


Question:
_______ function returns the current position of file pointer.
a. 

1.get( )

2. tell( )

3. cur( )

4. seek( )

Posted Date:-2021-12-12 06:44:55


Question:
_____________ function returns the strings

1.read( )

2.readline( )

3.Both of the above

4.None of the above

Posted Date:-2021-12-12 06:18:28


Question:
__________________ module is used for serializing and de-serializing any Python object structure.

1.pickle

2.unpickle

3.pandas

4.math

Posted Date:-2021-12-12 06:16:45


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
  51. Python MCQ Questions with Answer
  52. Test
  53. python mcq question and answer
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!